#!/usr/bin/env python
#coding=utf-8
import csv
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

class CaseElement:

	def __init__ (self, field):
		self.__field = field
		self.__value = self.__assort = "" 

	def setValue(self, value):
		self.__value = value

	def setAssort(self, assort):
		#0 = irrational, 1 = rational
		self.__assort = assort

	def getAssort(self):
		return self.__assort

	def getField(self):
		return self.__field

	def getValue(self):
		return self.__value

class CaseSet:
	def __init__ (self):
		self.__caseField = self.__caseName = self.__caseRule = ""
		self.__caseSet = []

	def addCaseSet(self, assort, value):
		caseElement = CaseElement(self.__caseField)
		caseElement.setValue(value)
		caseElement.setAssort(assort)
		self.__caseSet.append(caseElement)

	def setCaseField(self, caseField):
		self.__caseField = caseField

	def setCaseName(self, caseName):
		self.__caseName = caseName

	def setCaseRule(self, caseRule):
		self.__caseRule = caseRule
		
	def getCaseField(self):
		return self.__caseField

	def getCaseName(self):
		return self.__caseName

	def getCaseRule(Self):
		return self.__caseRule

	def getCaseSet(self):
		return self.__caseSet

class CaseData:
	def __init__(self):
		self.__allCaseData = []
		self.__numCaseSet = 0

	def importCSVData(self, path):
		f=open(PATH_DIR,'rb')
		reader=csv.reader(f)
		currentCaseField = ""
		isFirstLine = True
		isFirstTime = True
		for line in reader:
			#print line
			if isFirstLine != True:
				if currentCaseField != line[0]:
					if isFirstTime != True:
						self.__allCaseData.append(caseSet)
						self.__numCaseSet += 1
					isFirstTime = False
					currentCaseField = line[0]
					caseSet = CaseSet()
					caseSet.setCaseField(line[0])
					caseSet.setCaseName(line[1])
					caseSet.setCaseRule(line[3])
				else:
					#print line[2]+" "+line[3]
					caseSet.addCaseSet(line[2], line[3])
			else:
				isFirstLine = False
		self.__allCaseData.append(caseSet)
		self.__numCaseSet += 1
		f.close()
		#print self.__allCaseData[1].getCaseName()

	def getAllCaseData(self):
		return self.__allCaseData

PATH_DIR = "testCase.csv"
caseData = CaseData()
caseData.importCSVData(PATH_DIR)
print caseData.getAllCaseData()[1].getCaseSet()[0].getValue()